/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package ac.engin.treasury;

import ac.lib.data.dateTime;
import ac.settings.dataModel;
import ac.uitls.propertiesOperation;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.Date;

/**
 *
 * @author ismail
 */
public class Installment extends ac.ui.FrameOperationTemplat implements dataModel {

    public String thisId = "0";
    propertiesOperation po = new propertiesOperation();

    public String getidFromItems(String iid) {
        return db.getRow(TABLE_installment_items, "Installment_id", "id=" + iid)[0];
    }

    public String getLast() {

        return db.getRow(TABLE_installment, "max(id)", "1=1")[0];

    }

    public String getStatus(String id) {

        return db.getRow(TABLE_installment_items, "status", "id=" + id)[0];

    }

    public String getPyId(String id) {
        String pid = db.getRow(TABLE_installment_items, "pay_id", "id=" + id)[0];
        return pid;

    }

    public int updateStatus(String id, String status, String payID) {

        String[][] usedata = {new String[]{"status", "pay_id"}, new String[]{status, payID}};

        db.setUpdate(TABLE_installment_items, usedata, "id='" + id + "'");
        return db.retuenstatus;

    }

    public void crateInstallMent(double numbers, double amount, double Evrey) throws ParseException {

        double iamount = amount / numbers;
        for (int i = 0; i < numbers; i++) {
            int moreDays = i * (int) Evrey;
            Date d = dateTime.addDays(new Date(), moreDays);
            System.out.print("" + d + "-" + iamount);

            DecimalFormat df = new DecimalFormat("#.##");

            dataSaveValues = new String[]{thisId, "" + (i + 1), dateTime.updateDateFormat("todb", d), "" + df.format(iamount)};
            sendMessage = false;
            addStep2(true, false, false);

        }

    }

    //<editor-fold defaultstate="collapsed" desc="treasury">
    public void installPay(String id) {

        ac.GUI.index.jtab_pages.openPanel(new ac.GUI.treasury.treasuryIn("Installnotsaved", new String[]{id}), po.getWord("label.treasuryin"));

    }

    public void gotoPay(String id) {

        ac.GUI.index.jtab_pages.openPanel(new ac.GUI.treasury.treasuryIn("search", new String[]{"id", id}), po.getWord("label.treasuryin"));

    }
//</editor-fold>

}
